libdir = ${exec_prefix}/lib${LIBSUFFIX}
pkglibdir = $(libdir)/$(mypkglibdir)

SUBDIRS =

# Apps and files included in BUILT_SOURCES are compiled/created first.
# It must include qpp since qpp is required to generate some cpp's
BUILT_SOURCES = dummy

dummy:
	echo "Build started!"

EXTRA_INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_builddir)/lib
libqore_la_LDFLAGS = -version-info 18:0:13 -no-undefined ${QORE_LIB_LDFLAGS}
AM_CPPFLAGS = $(EXTRA_INCLUDES) ${QORE_LIB_CPPFLAGS}
AM_CXXFLAGS = ${QORE_LIB_CXXFLAGS}
AM_YFLAGS = -d

lib_LTLIBRARIES = libqore.la

bin_PROGRAMS = qpp

qpp_SOURCES = qpp.cpp

if COND_NEED_GETOPT_LONG
qpp_SOURCES += getopt_long.cpp
endif

if COND_MINGWCC
BUILT_SOURCES += qpp_native
QPP=./qpp_native
qpp_native: $(qpp_SOURCES)
	$(NATIVE_CXX) $(EXTRA_INCLUDES) $(NATIVE_CPPFLAGS) $(QPP_CPPFLAGS) $(NATIVE_LDFLAGS) -o $@ $(qpp_SOURCES)
else
QPP=./qpp$(EXEEXT)
BUILT_SOURCES += ./qpp$(EXEEXT)
endif

QORE_PSEUDO_SRC = Pseudo_QC_All.cpp Pseudo_QC_Bool.cpp Pseudo_QC_Int.cpp \
	Pseudo_QC_Float.cpp Pseudo_QC_Date.cpp Pseudo_QC_Object.cpp \
	Pseudo_QC_Hash.cpp Pseudo_QC_String.cpp Pseudo_QC_Binary.cpp \
	Pseudo_QC_List.cpp Pseudo_QC_Closure.cpp Pseudo_QC_Callref.cpp \
	Pseudo_QC_Nothing.cpp Pseudo_QC_Number.cpp

QORE_QPP_TARGETS = QC_Queue.cpp QC_Socket.cpp QC_ReadOnlyFile.cpp QC_File.cpp QC_AbstractSmartLock.cpp \
        QC_Mutex.cpp QC_AutoLock.cpp \
	QC_Gate.cpp QC_AutoGate.cpp QC_RWLock.cpp QC_AutoReadLock.cpp QC_AutoWriteLock.cpp \
	QC_Condition.cpp QC_Sequence.cpp QC_Counter.cpp QC_HTTPClient.cpp QC_FtpClient.cpp \
	QC_AbstractIterator.cpp QC_AbstractQuantifiedIterator.cpp \
	QC_AbstractBidirectionalIterator.cpp QC_AbstractQuantifiedBidirectionalIterator.cpp \
	QC_ListIterator.cpp QC_ListReverseIterator.cpp \
	QC_HashIterator.cpp QC_HashReverseIterator.cpp \
	QC_HashKeyIterator.cpp QC_HashKeyReverseIterator.cpp \
	QC_HashPairIterator.cpp QC_HashPairReverseIterator.cpp \
	QC_ObjectIterator.cpp QC_ObjectReverseIterator.cpp \
	QC_ObjectKeyIterator.cpp QC_ObjectKeyReverseIterator.cpp \
	QC_ObjectPairIterator.cpp QC_ObjectPairReverseIterator.cpp \
	QC_HashListIterator.cpp QC_HashListReverseIterator.cpp \
	QC_ListHashIterator.cpp QC_ListHashReverseIterator.cpp \
	QC_FileLineIterator.cpp QC_SingleValueIterator.cpp \
	QC_DataLineIterator.cpp \
	QC_RangeIterator.cpp \
	QC_ThreadPool.cpp \
	QC_TreeMap.cpp \
	QC_AbstractDatasource.cpp \
	QC_Datasource.cpp QC_DatasourcePool.cpp QC_SQLStatement.cpp QC_Dir.cpp QC_Program.cpp \
	QC_GetOpt.cpp QC_TermIOS.cpp QC_TimeZone.cpp QC_SSLCertificate.cpp QC_SSLPrivateKey.cpp \
	ql_misc.cpp ql_compression.cpp ql_thread.cpp ql_crypto.cpp ql_lib.cpp ql_file.cpp \
	ql_string.cpp ql_time.cpp ql_math.cpp ql_list.cpp ql_pwd.cpp ql_object.cpp \
	ql_dbi.cpp ql_context.cpp ql_env.cpp ql_type.cpp \
	qc_option.cpp qc_errno.cpp qc_qore.cpp

QorePseudoMethods.cpp: $(QORE_PSEUDO_SRC)

QORE_GENERATED_SOURCES = $(QORE_QPP_TARGETS) #parser.cpp parser.hpp scanner.cpp

dox-src: $(QORE_GENERATED_SOURCES)

QORE_ALL_SRC = $(QORE_GENERATED_SOURCES) $(QORE_PSEUDO_SRC)

QORE_ALL_QPP_SRC = $(subst cpp,qpp,$(QORE_QPP_TARGETS) $(QORE_PSEUDO_SRC))

$(QORE_QPP_TARGETS) $(QORE_PSEUDO_SRC): %.cpp: %.qpp qpp
	$(QPP) -V $< -o $@

CLEANFILES = $(QORE_ALL_SRC)

# only copy parser.h to parser.hpp as automake < 1.12 will still expect parser.h in the dist file :-(
parser.hpp: dummy
	if [ -f parser.h -a \( ! -f parser.hpp -o \( parser.h -nt parser.hpp \) \) ]; then cp parser.h parser.hpp; fi
parser.cpp: parser.ypp
scanner.cpp: scanner.lpp

if COND_SINGLE_COMPILATION_UNIT
libqore_la_SOURCES = \
	single-compilation-unit.cpp

single-compilation-unit.cpp: parser.cpp parser.hpp scanner.cpp $(QORE_ALL_SRC)

else
nodist_libqore_la_SOURCES = $(QORE_GENERATED_SOURCES)

libqore_la_SOURCES = \
	parser.ypp \
	scanner.lpp \
	Operator.cpp \
	QoreTreeNode.cpp \
	BarewordNode.cpp \
	SelfVarrefNode.cpp \
	StaticClassVarRefNode.cpp \
	BackquoteNode.cpp \
	ContextrefNode.cpp \
	ComplexContextrefNode.cpp \
	ContextRowNode.cpp \
	VarRefNode.cpp \
	FunctionCallNode.cpp \
	ReferenceNode.cpp \
	ScopedRefNode.cpp \
	ClassRefNode.cpp \
	AbstractQoreNode.cpp \
	QoreStringNode.cpp \
	DateTimeNode.cpp \
	qore_date_private.cpp \
	QoreHashNode.cpp \
	BinaryNode.cpp \
	QoreBigIntNode.cpp \
	QoreBoolNode.cpp \
	QoreFloatNode.cpp \
	QoreNumberNode.cpp \
	QoreNullNode.cpp \
	QoreNothingNode.cpp \
	Function.cpp \
	BuiltinFunctionList.cpp \
	GlobalVariableList.cpp \
	FunctionList.cpp \
	AbstractStatement.cpp \
	OnBlockExitStatement.cpp \
	ExpressionStatement.cpp \
	ReturnStatement.cpp \
	StatementBlock.cpp \
	ContextStatement.cpp \
	SummarizeStatement.cpp \
	IfStatement.cpp \
	WhileStatement.cpp \
	DoWhileStatement.cpp \
	ForStatement.cpp \
	ForEachStatement.cpp \
	TryStatement.cpp \
	ThrowStatement.cpp \
	SwitchStatement.cpp \
	Variable.cpp \
	support.cpp \
	QoreType.cpp \
	ModuleManager.cpp \
	QoreException.cpp \
	ExceptionSink.cpp \
	QoreClass.cpp \
	Context.cpp \
	FindNode.cpp \
	charset.cpp \
	unicode-charmaps.cpp \
	QoreProgram.cpp \
	QoreNamespace.cpp \
	QoreNet.cpp \
	QoreURL.cpp \
	QoreFile.cpp \
	QoreDir.cpp \
	QoreSocket.cpp \
	DateTime.cpp \
	QoreLib.cpp \
	QoreTimeZoneManager.cpp \
	QoreString.cpp \
	QoreObject.cpp \
	QoreListNode.cpp \
	qore-main.cpp \
	QoreGetOpt.cpp \
	QoreFtpClient.cpp \
	DBI.cpp \
	Datasource.cpp \
	DatasourcePool.cpp \
	SQLStatement.cpp \
	QoreSQLStatement.cpp \
	ManagedDatasource.cpp \
	ReferenceArgumentHelper.cpp \
	ReferenceHelper.cpp \
	ConstantList.cpp \
	QoreClassList.cpp \
	ThreadResourceList.cpp \
	thread.cpp \
	VRMutex.cpp \
	VLock.cpp \
	QoreRWLock.cpp \
	AbstractSmartLock.cpp \
	ExecArgList.cpp \
	NamedScope.cpp \
	RWLock.cpp \
	QoreSSLBase.cpp \
	QoreSSLCertificate.cpp \
	QoreSSLPrivateKey.cpp \
	QoreSocketObject.cpp \
	QoreCondition.cpp \
	QoreQueue.cpp \
	QoreQueueHelper.cpp \
	QoreRegexNode.cpp \
	QoreRegexBase.cpp \
	RegexSubstNode.cpp \
	RegexTransNode.cpp \
	Sequence.cpp \
	QoreReferenceCounter.cpp \
	SystemEnvironment.cpp \
	SmartMutex.cpp \
	QoreCounter.cpp \
	CallReferenceNode.cpp \
	QoreClosureParseNode.cpp \
	QoreClosureNode.cpp \
	QoreImplicitArgumentNode.cpp \
	QoreImplicitElementNode.cpp \
	ParseOptionMap.cpp \
	QoreTypeInfo.cpp \
	QoreDeleteOperatorNode.cpp \
	QoreRemoveOperatorNode.cpp \
	QoreSpliceOperatorNode.cpp \
	QoreExtractOperatorNode.cpp \
	QoreCastOperatorNode.cpp \
	QoreUnaryMinusOperatorNode.cpp \
	QoreLogicalNotOperatorNode.cpp \
	QoreDotEvalOperatorNode.cpp \
	QoreLogicalEqualsOperatorNode.cpp \
	QoreModulaOperatorNode.cpp \
	QoreAssignmentOperatorNode.cpp \
	QoreIntAssignmentOperatorNode.cpp \
	QorePlusEqualsOperatorNode.cpp \
	QoreIntPlusEqualsOperatorNode.cpp \
	QoreMinusEqualsOperatorNode.cpp \
	QoreIntMinusEqualsOperatorNode.cpp \
        QoreOrEqualsOperatorNode.cpp \
        QoreAndEqualsOperatorNode.cpp \
        QoreModulaEqualsOperatorNode.cpp \
        QoreMultiplyEqualsOperatorNode.cpp \
        QoreDivideEqualsOperatorNode.cpp \
        QoreXorEqualsOperatorNode.cpp \
        QoreShiftLeftEqualsOperatorNode.cpp \
        QoreShiftRightEqualsOperatorNode.cpp \
	QorePostIncrementOperatorNode.cpp \
	QorePostDecrementOperatorNode.cpp \
	QorePreIncrementOperatorNode.cpp \
	QorePreDecrementOperatorNode.cpp \
	QoreIntPostIncrementOperatorNode.cpp \
	QoreIntPostDecrementOperatorNode.cpp \
	QoreIntPreIncrementOperatorNode.cpp \
	QoreIntPreDecrementOperatorNode.cpp \
	QoreLogicalLessThanOperatorNode.cpp \
	QoreLogicalGreaterThanOperatorNode.cpp \
	QoreMapOperatorNode.cpp \
	QoreMapSelectOperatorNode.cpp \
	QoreHashMapOperatorNode.cpp \
	QoreHashMapSelectOperatorNode.cpp \
	QoreNullCoalescingOperatorNode.cpp \
	QoreValueCoalescingOperatorNode.cpp \
	QoreChompOperatorNode.cpp \
	QoreTrimOperatorNode.cpp \
	QorePseudoMethods.cpp \
	QoreHTTPClient.cpp \
	QoreHttpClientObject.cpp \
	QoreValue.cpp \
	xxhash.cpp \
	minitest.cpp \
	QoreValueList.cpp

if COND_SIGNAL_HANDLING
libqore_la_SOURCES += QoreSignal.cpp
endif
if COND_DEBUG
libqore_la_SOURCES += ql_debug.cpp
endif
if COND_STACK_TRACE
libqore_la_SOURCES += CallStack.cpp
endif
if COND_NEED_GLOB
libqore_la_SOURCES += glob.cpp
endif
if COND_NEED_INET_NTOP
libqore_la_SOURCES += inet_ntop.cpp
endif
if COND_NEED_INET_PTON
libqore_la_SOURCES += inet_pton.cpp
endif
endif

if COND_SOLARIS_CC_X86_64
libqore_la_SOURCES += sunpro-x86_64.s
endif
if COND_SOLARIS_CC_I386
libqore_la_SOURCES += sunpro-i386.s
endif
if COND_SOLARIS_CC_SPARC32
libqore_la_SOURCES += sunpro-sparc32.s
endif
#if COND_SOLARIS_CC_SPARC64
#libqore_la_SOURCES += sunpro-sparc64.s
#endif
if COND_HPUX_ACC_PARISC32
libqore_la_SOURCES += acc-parisc32.s
endif
if COND_HPUX_ACC_64BIT_IA64
libqore_la_SOURCES += acc-64bit-ia64.s
endif
